package de.bht.fb6.cg1.exercise1;

import java.awt.Color;

/**
 * Represents a RGB color.
 * 
 * this object dosn't do much - rgb to rgb conversation is quite simple ;-)
 * <p>
 * this object is just used to talk to other {@link ColorModelInterface}
 * implementations like CMY or YUV.
 * 
 * @author Dominik Eckelmann
 * @see AbstractColorModel
 */
public class RGB extends AbstractColorModel {

    /**
     * creates a new RGB color.
     * 
     * @param c     initial color to apply
     */
    public RGB(final Color c) {
        super(c);
    }

    /**
     * sets the object to a new color.
     * 
     * @param color     to apply to the object
     * @return the new color in the RGB space as int[]
     */
    @Override
    public int[] setColor(final Color c) {
        color = new Color(c.getRed(), c.getGreen(), c.getBlue());
        modelColor = new int[] {
                c.getRed(), c.getGreen(), c.getBlue()
        };
        return modelColor;
    }

    /**
     * set the color by single components
     * 
     * @param color     int array with [R,G,B] values
     * @return the new color value.
     */
    @Override
    public Color setModelColor(final int[] color) {
        if (color.length != getComponentCount()) {
            throw new IllegalArgumentException();
        }
        this.color = new Color(color[0], color[1], color[2]);
        return this.color;
    }

    /**
     * color space name.
     * 
     * @return returns RGB, name of the color space.
     */
    @Override
    public String getName() {
        return "RGB";
    }

    /**
     * color space component count.
     * 
     * @return RGB has always 3 color components ;-)
     */
    @Override
    public int getComponentCount() {
        return 3;
    }

    /**
     * returns the range for every single component
     * 
     * RGB usualy is 0-255
     */
    @Override
    public Range[] getComponentRange() {
        final Range ranges[] = new Range[] {
                new Range(0, 255), new Range(0, 255), new Range(0, 255)
        };
        return ranges;
    }

}
